package com.example.xianji.activity;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.JsonObjectRequest;
import com.example.xianji.Contant;
import com.example.xianji.XJApplication;
import com.example.xianji.R;
import com.example.xianji.adapter.Birthday_Adapter;
import com.example.xianji.bean.YiJi_Class;

import com.example.xianji.constant.Constant;
import com.example.xianji.utils.sp.PreferenceEngine;
import com.example.xianji.widgets.Expanable_ListView;
import com.example.xianji.widgets.MyButton;
import com.example.xianji.widgets.MyButton.ButtonState;
import com.example.xianji.widgets.MyButton.OnToggleStateChangeListner;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.drawable.BitmapDrawable;
import android.text.ClipboardManager;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 个人编辑信息页面
 *
 * @author me
 */

public class Main_BianJi_XinxiActivity extends Activity implements
        OnClickListener {
    private EditText edittext_nickname, edittext_name, edittext_code,
            edittext_tel, edittext_ext, edittext_qq;
    private TextView textview_sex, textview_phone, textview_save,
            text_birthday, edittext_email;
    private Button change_phone;
    private ImageView bianji_xinxi_back;
    //    private SharedPreferences sp;
//    private Editor ed;
    private MyButton my_button;
    private LinearLayout linearlayout_sex, layout, linearlayout_birthday,
            layout1;
    private ListView show_listview;
    private PopupWindow show_popupWindow;
    private ClipboardManager clipboard;
    private InputMethodManager manager;
    private ArrayList<YiJi_Class> list = new ArrayList<YiJi_Class>();
    private Birthday_Adapter yiji_birthday_Adapter, erji_birthday_Adapter,
            sanji_birthday_Adapter;
    private String group[] = new String[]{"男", "女"},
            year_group[] = new String[]{"1960", "1961", "1962", "1963",
                    "1964", "1965", "1966", "1967", "1968", "1969", "1970",
                    "1971", "1972", "1973", "1974", "1975", "1976", "1977",
                    "1978", "1979", "1980", "1981", "1982", "1983", "1984",
                    "1985", "1986", "1987", "1988", "1989", "1990", "1991",
                    "1992", "1993", "1994", "1995", "1996", "1997", "1998",},
            month_group[] = new String[]{"01", "02", "03", "04", "05", "06",
                    "07", "08", "09", "10", "11", "12",},
            day_group[] = new String[]{"01", "02", "03", "04", "05", "06",
                    "07", "08", "09", "10", "11", "12", "13", "14", "15", "16",
                    "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
                    "27", "28", "29", "30"};
    private String sex, year, month, day;
    private Boolean sex_flag = false, year_flag = false, month_flag = false,
            day_flag = false;
    private Expanable_ListView yiji_listview, erji_listview, sanji_listview;
    private Button geren_button_privonce, geren_button_city,
            geren_button_distrct;

    private MyAdapter mMyAdapter;
    private int geren_province_id, geren_city_id, geren_distrct_id;
    private boolean geren_province_flag = false, geren_city_flag = false,
            isopen, geren_distrct_flag = false;
    public static int geren_save;

    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == 1) {
                show_listview.setAdapter(mMyAdapter);
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main__bian_ji__xinxi);
        // XJApplication.getInstance1().addActivity1(this);

        // XJApplication.getInstance().addActivity(this);
        edittext_nickname = (EditText) findViewById(R.id.edittext_nickname);
        edittext_name = (EditText) findViewById(R.id.edittext_name);
        textview_sex = (TextView) findViewById(R.id.textview_sex);
        text_birthday = (TextView) findViewById(R.id.text_birthday);
        edittext_email = (TextView) findViewById(R.id.edittext_email);
        textview_phone = (TextView) findViewById(R.id.textview_phone);
        edittext_code = (EditText) findViewById(R.id.edittext_code);
        edittext_tel = (EditText) findViewById(R.id.edittext_tel);
        edittext_ext = (EditText) findViewById(R.id.edittext_ext);
        edittext_qq = (EditText) findViewById(R.id.edittext_qq);
        change_phone = (Button) findViewById(R.id.change_phone);
        bianji_xinxi_back = (ImageView) findViewById(R.id.bianji_xinxi_back);
        textview_save = (TextView) findViewById(R.id.textview_save);
//        sp = getSharedPreferences("text", MODE_PRIVATE);
//        ed = sp.edit();
        my_button = (MyButton) findViewById(R.id.my_button);

        geren_button_privonce = (Button) findViewById(R.id.geren_button_privonce);
        geren_button_city = (Button) findViewById(R.id.geren_button_city);
        geren_button_distrct = (Button) findViewById(R.id.geren_button_distrct);

        linearlayout_sex = (LinearLayout) findViewById(R.id.linearlayout_sex);
        linearlayout_birthday = (LinearLayout) findViewById(R.id.linearlayout_birthday);

        clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

        if (getIntent().getIntExtra("isMobile", 0) == Contant.not_mobile) {
            // 没有手机号登陆后跳转到编辑信息页面
            get_information_data();// 获取信息
            change_phone.setText("新增手机号");

        } else {
            // 个人后台跳转过来的编辑信息
            change_phone.setText("修改手机号");

            geren_button_privonce.setText(getIntent().getStringExtra(
                    "province_name"));
            if (geren_button_privonce.getText().toString().equals("北京")
                    || geren_button_privonce.getText().toString().equals("上海")
                    || geren_button_privonce.getText().toString().equals("天津")
                    || geren_button_privonce.getText().toString().equals("香港")
                    || geren_button_privonce.getText().toString().equals("台湾")) {
                geren_button_city.setText(getIntent().getStringExtra(
                        "province_name"));
                if (getIntent().getStringExtra("city_name").length() == 0) {
                    geren_button_distrct.setText(getIntent().getStringExtra(
                            "district_name"));
                } else {
                    geren_button_distrct.setText(getIntent().getStringExtra(
                            "city_name"));
                }
            } else {
                geren_button_city.setText(getIntent().getStringExtra(
                        "city_name"));
                geren_button_distrct.setText(getIntent().getStringExtra(
                        "district_name"));
            }
            textview_phone.setText(getIntent().getStringExtra("phone"));

            if (getIntent().getStringExtra("province_name").length() > 0) {
                geren_province_flag = true;

                if (geren_button_privonce.getText().toString().equals("北京")
                        || geren_button_privonce.getText().toString()
                        .equals("上海")
                        || geren_button_privonce.getText().toString()
                        .equals("天津")
                        || geren_button_privonce.getText().toString()
                        .equals("香港")
                        || geren_button_privonce.getText().toString()
                        .equals("台湾")) {

                    geren_city_flag = true;
                } else if (getIntent().getStringExtra("city_name").length() > 0) {
                    geren_city_flag = true;

                }
            }

            geren_province_id = getIntent().getIntExtra("geren_province_id", 0);
            geren_city_id = getIntent().getIntExtra("geren_city_id", 0);
            geren_distrct_id = getIntent().getIntExtra("geren_district_id", 0);

            isopen = getIntent().getBooleanExtra("isopen", false);

            edittext_nickname.setText(getIntent().getStringExtra("nickname"));
            edittext_name.setText(getIntent().getStringExtra("name"));
            textview_sex.setText(getIntent().getStringExtra("sex"));
            text_birthday.setText(getIntent().getStringExtra("birthday"));
            edittext_email.setText(getIntent().getStringExtra("email"));

            edittext_code.setText(getIntent().getStringExtra("code"));
            edittext_tel.setText(getIntent().getStringExtra("tel"));
            edittext_ext.setText(getIntent().getStringExtra("ext"));
            edittext_qq.setText(getIntent().getStringExtra("QQ"));

        }

        if (isopen) {
            my_button.setSlideBackgroundResourse(R.drawable.anniu);
            my_button.setSwitchBackgroundResourse(R.drawable.kaiguan1);
            my_button.setButtonState(ButtonState.open);
        } else {
            my_button.setSlideBackgroundResourse(R.drawable.anniu);
            my_button.setSwitchBackgroundResourse(R.drawable.kaiguan);
            my_button.setButtonState(ButtonState.close);

        }
        my_button
                .setOnToggleStateChangeListner(new OnToggleStateChangeListner() {

                    @Override
                    public void OnToggleStateChange(ButtonState buttonState) {
                        if (buttonState == ButtonState.open) {

                            my_button
                                    .setSlideBackgroundResourse(R.drawable.anniu);
                            my_button
                                    .setSwitchBackgroundResourse(R.drawable.kaiguan1);
                            my_button.setButtonState(ButtonState.open);
                            isopen = true;

                        } else {
                            isopen = false;
                            my_button
                                    .setSlideBackgroundResourse(R.drawable.anniu);
                            my_button
                                    .setSwitchBackgroundResourse(R.drawable.kaiguan);
                            my_button.setButtonState(ButtonState.close);
                        }
                    }
                });

        change_phone.setOnClickListener(this);
        bianji_xinxi_back.setOnClickListener(this);
        linearlayout_sex.setOnClickListener(this);

        linearlayout_birthday.setOnClickListener(this);
        textview_save.setOnClickListener(this);

        geren_button_privonce.setOnClickListener(this);
        geren_button_city.setOnClickListener(this);
        geren_button_distrct.setOnClickListener(this);
    }

    public void get_information_data() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", getIntent().getStringExtra("xianji_token"));

        JSONObject parmas = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST,
                Contant.yonghu_infor, parmas, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {

                try {
                    if (response.getInt("status") == 1) {

                        JSONArray array = response.getJSONArray("data");

                        for (int i = 0; i < array.length(); i++) {
                            JSONObject object = array.getJSONObject(0);
                            JSONObject object1 = array.getJSONObject(1);
                            edittext_nickname.setText(object
                                    .getString("nickname"));

                            edittext_name.setText(object1
                                    .getString("name"));

                            if (object1.getString("sex").equals("Y")) {
                                textview_sex.setText("男");

                            } else if (object1.getString("sex").equals(
                                    "N")) {
                                textview_sex.setText("女");

                            }
                            geren_button_privonce.setText(object1
                                    .getString("province_name"));
                            if (object1.getString("province_name")
                                    .equals("北京")
                                    || object1.getString(
                                    "province_name").equals(
                                    "上海")
                                    || object1.getString(
                                    "province_name").equals(
                                    "天津")
                                    || object1.getString(
                                    "province_name").equals(
                                    "香港")
                                    || object1.getString(
                                    "province_name").equals(
                                    "台湾")) {

                                geren_button_city.setText(object1
                                        .getString("province_name"));
                                if (object1.getString("city_name")
                                        .length() > 0) {
                                    geren_button_distrct.setText(object1
                                            .getString("city_name"));
                                } else {
                                    geren_button_distrct.setText(object1
                                            .getString("district_name"));
                                }

                            } else {
                                geren_button_city.setText(object1
                                        .getString("city_name"));
                                geren_button_distrct.setText(object1
                                        .getString("district_name"));

                            }

                            geren_province_id = object1
                                    .getInt("province");
                            geren_city_id = object1.getInt("city");
                            geren_distrct_id = object1
                                    .getInt("district");

                            if (object1.getInt("isopen") == 0) {
                                isopen = false;
                            } else {
                                isopen = true;
                            }

                            edittext_code.setText(object1
                                    .getString("code"));
                            edittext_tel.setText(object1
                                    .getString("tel"));
                            edittext_ext.setText(object1
                                    .getString("ext"));

                            edittext_email.setText(object
                                    .getString("email"));

                            edittext_qq.setText(object1.getString("qq"));
                            if (object1.getString("birth").equals(
                                    "0000-00-00")) {
                                text_birthday.setText("");

                            } else {

                                text_birthday.setText(object1
                                        .getString("birth"));
                            }

                        }

                    } else {

                        // Toast.makeText(getActivity(),response.getString("msg"),0).show();
                    }


                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();

    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.change_phone) {
            Intent intent = new Intent(Main_BianJi_XinxiActivity.this,
                    Main_Regesiter_OneActivity.class);
            if (getIntent().getIntExtra("isMobile", 0) == Contant.not_mobile) {
                // 登陆后没有手机号跳转到新增手机号
                intent.putExtra("from", 3);
                intent.putExtra("xianji_token",
                        getIntent().getStringExtra("xianji_token"));
            } else {
                // 登陆后没有手机号跳转到修改手机号
                intent.putExtra("from", 2);
            }

            startActivity(intent);

        } else if (v.getId() == R.id.bianji_xinxi_back) {
            this.setResult(Contant.back_resultCode);
            this.finish();

        } else if (v.getId() == R.id.linearlayout_sex) {
            Photo_show();
            show_popupWindow.setHeight(500);
            show_listview.setAdapter(new ArrayAdapter<String>(
                    Main_BianJi_XinxiActivity.this,
                    R.layout.information_show_photo_item,
                    R.id.show_photo_item_text, group));
            show_popupWindow.showAtLocation(findViewById(R.id.bianji_xinxi),
                    Gravity.BOTTOM, 0, 0);
            show_listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int arg2, long arg3) {
                    textview_sex.setText(group[arg2]);
                    if (group[arg2].equals("男")) {
                        sex = "Y";
                    } else if (group[arg2].equals("女")) {
                        sex = "N";
                    }
                    sex_flag = true;
                    if (show_popupWindow != null) {
                        show_popupWindow.dismiss();
                        show_popupWindow = null;
                    }
                }
            });
        } else if (v.getId() == R.id.linearlayout_birthday) {
            birthday_popupwindow();
            yiji_birthday_Adapter = new Birthday_Adapter(this, year_group);
            erji_birthday_Adapter = new Birthday_Adapter(this, month_group);
            sanji_birthday_Adapter = new Birthday_Adapter(this, day_group);
            yiji_listview.setAdapter(yiji_birthday_Adapter);

            erji_listview.setAdapter(erji_birthday_Adapter);
            sanji_listview.setAdapter(sanji_birthday_Adapter);

            show_popupWindow.showAtLocation(findViewById(R.id.bianji_xinxi),
                    Gravity.BOTTOM, 0, 0);

            yiji_listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int arg2, long arg3) {
                    yiji_birthday_Adapter.setPosition(arg2);
                    yiji_birthday_Adapter.notifyDataSetChanged();
                    year_flag = true;
                    year = year_group[arg2];
                }
            });

            erji_listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int arg2, long arg3) {
                    erji_birthday_Adapter.setPosition(arg2);
                    erji_birthday_Adapter.notifyDataSetChanged();
                    month_flag = true;
                    month = month_group[arg2];
                }
            });

            sanji_listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int arg2, long arg3) {
                    day_flag = true;
                    if (year_flag && month_flag) {
                        if (show_popupWindow != null) {

                            show_popupWindow.dismiss();
                            show_popupWindow = null;
                        }
                        text_birthday.setText(year + "-" + month + "-"
                                + day_group[arg2]);
                    }
                }
            });

        } else if (v.getId() == R.id.textview_save) {
            if (textview_phone.getText().toString().length() > 0) {
                geren_save = 1;
                save_info();
            } else {
                Toast.makeText(Main_BianJi_XinxiActivity.this, "请输入手机号", Toast.LENGTH_SHORT).show();
            }
        } else if (v.getId() == R.id.geren_button_privonce) {
            Photo_show();
            show_popupWindow.setHeight(700);
            show_popupWindow.showAtLocation(findViewById(R.id.bianji_xinxi),
                    Gravity.BOTTOM, 0, 0);
            get_province();
            show_listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int arg2, long arg3) {
                    geren_button_privonce.setText(list.get(arg2).getName());
                    geren_button_privonce.setTextColor(getResources().getColor(
                            R.color.black3F));
                    geren_province_id = list.get(arg2).getId();
                    geren_province_flag = true;
                    geren_button_city.setText("请选择城市");
                    geren_button_city.setTextColor(getResources().getColor(
                            R.color.gray98));
                    geren_button_distrct.setText("请选择区");
                    geren_button_distrct.setTextColor(getResources().getColor(
                            R.color.gray98));
                    geren_city_flag = false;
                    geren_distrct_flag = false;
                    if (show_popupWindow != null) {
                        show_popupWindow.dismiss();
                        show_popupWindow = null;
                    }
                }
            });

        } else if (v.getId() == R.id.geren_button_city) {
            if (geren_province_flag) {
                Photo_show();
                show_popupWindow.setHeight(700);
                show_popupWindow.showAtLocation(
                        findViewById(R.id.bianji_xinxi), Gravity.BOTTOM, 0, 0);

                if (geren_button_privonce.getText().toString().equals("北京")
                        || geren_button_privonce.getText().toString()
                        .equals("上海")
                        || geren_button_privonce.getText().toString()
                        .equals("天津")
                        || geren_button_privonce.getText().toString()
                        .equals("香港")
                        || geren_button_privonce.getText().toString()
                        .equals("台湾")) {

                    get_teshu_province();

                } else {

                    get_city();
                }

                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1,
                                            int arg2, long arg3) {
                        geren_button_city.setText(list.get(arg2).getName());
                        geren_button_city.setTextColor(getResources().getColor(
                                R.color.black3F));
                        if (geren_button_privonce.getText().toString()
                                .equals("北京")
                                || geren_button_privonce.getText().toString()
                                .equals("上海")
                                || geren_button_privonce.getText().toString()
                                .equals("天津")
                                || geren_button_privonce.getText().toString()
                                .equals("香港")
                                || geren_button_privonce.getText().toString()
                                .equals("台湾")) {
                            geren_city_id = 0;
                        } else {
                            geren_city_id = list.get(arg2).getId();
                        }
                        geren_city_flag = true;

                        geren_button_distrct.setText("请选择区");
                        geren_button_distrct.setTextColor(getResources()
                                .getColor(R.color.gray98));
                        geren_distrct_flag = false;
                        if (show_popupWindow != null) {
                            show_popupWindow.dismiss();
                            show_popupWindow = null;
                        }
                    }
                });
            } else {
                Toast.makeText(Main_BianJi_XinxiActivity.this, "请先选择省份", Toast.LENGTH_SHORT)
                        .show();
            }
        } else if (v.getId() == R.id.geren_button_distrct) {
            if (geren_city_flag) {
                Photo_show();
                show_popupWindow.setHeight(700);
                show_popupWindow.showAtLocation(
                        findViewById(R.id.bianji_xinxi), Gravity.BOTTOM, 0, 0);
                get_district();
                show_listview.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> arg0, View arg1,
                                            int arg2, long arg3) {
                        geren_button_distrct.setText(list.get(arg2).getName());
                        geren_button_distrct.setTextColor(getResources()
                                .getColor(R.color.black3F));
                        geren_distrct_id = list.get(arg2).getId();
                        geren_distrct_flag = true;
                        if (show_popupWindow != null) {
                            show_popupWindow.dismiss();
                            show_popupWindow = null;
                        }
                    }
                });
            } else {
                Toast.makeText(Main_BianJi_XinxiActivity.this, "请先选择省份", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }

    /**
     * 省份请求
     */
    public void get_province() {
        HashMap<String, Object> map = new HashMap<String, Object>();

        map.put("pid", 0);
        Log.i("进入进入进入", "进入进入进入");

        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST,
                Contant.place, params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));

                            list.add(mYiJi_Class);
                        }
                    } else {
                        Toast.makeText(Main_BianJi_XinxiActivity.this,
                                response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                    handler.sendEmptyMessage(1);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    /**
     * 省份请求
     */
    public void get_teshu_province() {
        list.clear();
        YiJi_Class mYiJi_Class = new YiJi_Class();
        mYiJi_Class.setId(geren_province_id);
        mYiJi_Class.setName(geren_button_privonce.getText().toString());

        list.add(mYiJi_Class);
        handler.sendEmptyMessage(1);

    }

    /**
     * 城市请求
     */
    public void get_district() {

        HashMap<String, Object> map = new HashMap<String, Object>();
        if (geren_button_privonce.getText().toString().equals("北京")
                || geren_button_privonce.getText().toString().equals("上海")
                || geren_button_privonce.getText().toString().equals("天津")
                || geren_button_privonce.getText().toString().equals("香港")
                || geren_button_privonce.getText().toString().equals("台湾")) {
            map.put("pid", geren_province_id);
        } else {

            map.put("pid", geren_city_id);
        }
        Log.i("进入进入进入", "进入进入进入");

        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST,
                Contant.place, params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));
                            list.add(mYiJi_Class);
                        }

                    } else {
                        Toast.makeText(Main_BianJi_XinxiActivity.this,
                                response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                    handler.sendEmptyMessage(1);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();

    }

    /**
     * 地区请求
     */
    public void get_city() {

        HashMap<String, Object> map = new HashMap<String, Object>();

        map.put("pid", geren_province_id);
        Log.i("进入进入进入", "进入进入进入");

        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST,
                Contant.place, params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        list.clear();
                        JSONArray array = response.getJSONArray("data");
                        for (int i = 0; i < array.length(); i++) {
                            JSONObject obj = array.getJSONObject(i);
                            YiJi_Class mYiJi_Class = new YiJi_Class();
                            mYiJi_Class.setId(obj.getInt("id"));
                            mYiJi_Class.setName(obj.getString("name"));
                            list.add(mYiJi_Class);
                        }

                    } else {
                        Toast.makeText(Main_BianJi_XinxiActivity.this,
                                response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                    handler.sendEmptyMessage(1);
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                if (show_popupWindow != null) {
                    show_popupWindow.dismiss();
                    show_popupWindow = null;
                }
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();

    }

    public void save_info() {
        Log.i("进入今日进入", "进入今日进入");
        HashMap<String, Object> map = new HashMap<String, Object>();
        if (getIntent().getIntExtra("isMobile", 0) == Contant.not_mobile) {
            map.put("token", getIntent().getStringExtra("xianji_token"));
        } else {
            map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
//            map.put("token", sp.getString("xianji_token", ""));
        }

        map.put("nickname", edittext_nickname.getText().toString());

        map.put("name", edittext_name.getText().toString());

        map.put("birth", text_birthday.getText().toString());

        map.put("email", edittext_email.getText().toString());

        map.put("mobile", textview_phone.getText().toString());

        map.put("province", geren_province_id);
        map.put("city", geren_city_id);
        map.put("district", geren_distrct_id);

        map.put("qq", edittext_qq.getText().toString());
        if (textview_sex.getText().equals("男")) {
            map.put("sex", "Y");

        } else if (textview_sex.getText().equals("女")) {
            map.put("sex", "N");
        }
        map.put("code", edittext_code.getText().toString());

        map.put("tel", edittext_tel.getText().toString());

        map.put("ext", edittext_ext.getText().toString());
        Log.i("sddddddd", isopen + "");

        if (isopen) {
            map.put("isopen", 1);

        } else {
            map.put("isopen", 0);
        }
        JSONObject parmas = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST,
                Contant.save_info, parmas, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        Toast.makeText(Main_BianJi_XinxiActivity.this,
                                response.getString("msg"), Toast.LENGTH_SHORT).show();
                        if (getIntent().getIntExtra("isMobile", 0) == Contant.not_mobile) {
                            // 没有手机号登陆后跳转到编辑页面
                            // 保存完信息后把静态手机号的赋值置空
                            Main_Change_phone_numberActivity.Change_Phone = "";
                            PreferenceEngine.getInstance().putBoolean(Constant.SP.NAME, Constant.SP.KEY_XIANJI_DENGLU, true);
//                            ed.putBoolean("xianji_denglu", true);
                            PreferenceEngine.getInstance().putString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, getIntent().getStringExtra("xianji_token"));
//                            ed.putString("xianji_token", getIntent().getStringExtra("xianji_token"));
                            PreferenceEngine.getInstance().putInt(Constant.SP.NAME, Constant.SP.KEY_FINISH_FROM, 2);
//                            ed.putInt("finish_from", 2);
                            PreferenceEngine.getInstance().putInt(Constant.SP.NAME, Constant.SP.KEY_MY_XIANJI_SET, 2);
//                            ed.putInt("my_xianji_set", 2);
//                            ed.commit();
                            // 来自于服务详情页面的登录成功赋值为2
                            if (Contant.come_from_fuwuDetail == 1) {
                                Contant.come_from_fuwuDetail = 2;
                            }
                            Contant.login_resume = 1;
                            // 如果从登录页面登录成功后则设置为0，如果是点返回键回到"我的后台"则是1，得加载数据
                            Contant.change_password_login = 0;
                        } else {
                            // 有手机号个人后台跳转到编辑页面
                            Main_BianJi_XinxiActivity.this
                                    .setResult(Contant.back_resultCode);
                        }
                        Main_BianJi_XinxiActivity.this.finish();
                    } else {
                        Toast.makeText(Main_BianJi_XinxiActivity.this,
                                response.getString("msg"), Toast.LENGTH_SHORT).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    private void Photo_show() {
        layout = (LinearLayout) LayoutInflater.from(
                Main_BianJi_XinxiActivity.this).inflate(
                R.layout.information_shoow_photo, null);
        show_listview = (ListView) layout
                .findViewById(R.id.information_photo_listview);

        show_listview.setCacheColorHint(0);
        mMyAdapter = new MyAdapter();
        show_popupWindow = new PopupWindow(layout,
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT);
        show_popupWindow.setBackgroundDrawable(new BitmapDrawable());

        show_popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
        show_popupWindow.update();
        show_popupWindow.setOutsideTouchable(true);
        show_popupWindow.setFocusable(true);
        show_popupWindow.setContentView(layout);
    }

    private void birthday_popupwindow() {
        layout1 = (LinearLayout) LayoutInflater.from(
                Main_BianJi_XinxiActivity.this).inflate(
                R.layout.birthday_listview, null);
        yiji_listview = (Expanable_ListView) layout1
                .findViewById(R.id.yiji_Expanable_ListView);
        erji_listview = (Expanable_ListView) layout1
                .findViewById(R.id.erji_Expanable_ListView);
        sanji_listview = (Expanable_ListView) layout1
                .findViewById(R.id.sanji_Expanable_ListView);
        yiji_listview.setCacheColorHint(0);
        erji_listview.setCacheColorHint(0);
        sanji_listview.setCacheColorHint(0);

        show_popupWindow = new PopupWindow(layout1,
                WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT);
        show_popupWindow.setBackgroundDrawable(new BitmapDrawable());

        show_popupWindow.setHeight(700);
        show_popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
        show_popupWindow.update();
        show_popupWindow.setOutsideTouchable(true);
        show_popupWindow.setFocusable(true);
        show_popupWindow.setContentView(layout1);
    }

    /**
     * 隐藏软键盘
     */
    private void hideKeyboard() {
        if (getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) {
            if (getCurrentFocus() != null)
                manager.hideSoftInputFromWindow(getCurrentFocus()
                        .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

        }
    }

    class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int arg0) {
            return arg0;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Holder mHolder;
            if (convertView == null) {
                mHolder = new Holder();
                convertView = View.inflate(Main_BianJi_XinxiActivity.this,
                        R.layout.listview_item_layout, null);
                mHolder.place_text = (TextView) convertView
                        .findViewById(R.id.place_text);
                convertView.setTag(mHolder);
            }
            mHolder = (Holder) convertView.getTag();
            mHolder.place_text.setText(list.get(position).getName());

            return convertView;
        }
    }
    class Holder {
        TextView place_text;

    }

    @Override
    protected void onResume() {
        super.onResume();
        if (Main_Change_phone_numberActivity.Change_Phone.length() > 0) {
            textview_phone
                    .setText(Main_Change_phone_numberActivity.Change_Phone);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }
}
